﻿using Assets.Scripts.DL.Consts;
using Assets.Scripts.DL.Mgrs;
using TMPro;
using UnityEngine;

public class PlayerBow : PlayerBaseState {
	bool _sendArrow;
	public PlayerBow(PlayerController controller, PlayerStateEnum stateName, State<PlayerStateEnum> superFSM, StateFactory<PlayerStateEnum> factory) : base(controller, stateName, superFSM, factory) {
		AddConditionToSelf(() => controller.BowInput);

	}

	public override void Enter() {
		if (_controller.IsOnGround) {
			_controller.PlayAnim(PlayerStateEnum.GrdBow);
			_controller.Velocity = Vector2.zero;
		}
		else {
			//Debug.Log("AirBow");
			_controller.PlayAnim(PlayerStateEnum.AirBow);
			var tmp = _controller.Velocity;
			_controller.Velocity = new UnityEngine.Vector2(tmp.x, 0);
		}
		_sendArrow = false;
		AudioManager.Play(_controller.StateAudio, AudioStr.BowReady);
	}
	public override void Update() {
		base.Update();
		if (_controller.IsAnimPlayAt(0.9f) && !_sendArrow) {
			AudioManager.Play(_controller.Effect, AudioStr.BowOut);
			var pos = _controller.transform.position;
			var off = _controller.ConfigData.MakeArrowOffset;
			var dir = _controller.transform.localScale.x;
			var v = new Vector2(_controller.ConfigData.ArrowSpeed * dir, 0);
			PoolTools.MakeArrow(pos + (Vector3)off, v, Tags.PlayerRemoteAtk, _controller.ConfigData.BowDamage + _controller.StateData.BowExAtk);
			_sendArrow = true;
			//Debug.Log(1);
		}
	}
	public override void Exit() {
	}
}